define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'pms/pmseventlogs/index' + location.search,
                    table: 'pms_event_logs',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                searchFormVisible: true,
                columns: [
                    [
                        {field: 'id', title: __('Id'), operate: false},
                        {field: 'res_type', title: __('Res_type'), searchList: {'order':'订单', 'reserve': '预定单'}, formatter: Table.api.formatter.label},
                        {field: 'res_no', title: __('资源编号'), operate: 'LIKE'},
                        {field: 'detail', title: __('Detail'), operate: false, align: 'left'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'creator_nickname', title: __('Creator'), operate: false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate, buttons: [{
                                name: '详情',
                                title: __('详情'),
                                classname: 'btn btn-xs btn-info btn-dialog',
                                text: '详情',
                                icon: 'fa fa-file-text-o',
                                extend: 'data-area=\'["80%","80%"]\'',
                                url: 'pms/pmseventlogs/detail'
                            }]}
                    ]
                ]
            });

            //双击编辑
            $(table).on("dblclick", "tr", function(e){
                e.preventDefault();
                $(this).find('.btn-dialog').click();
            });
            
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        detail: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});